﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.Auditing;
using Abp.Web.Models;
using FwProject.Controllers;
using FwProject.Keyword;
using FwProject.Keyword.Dto;
using Microsoft.AspNetCore.Mvc;

namespace FwProject.Web.Shop.Controllers
{
    
    public class KeywordController: FwProjectControllerBase
    {
        private readonly IKeywordAppService _keywordAppService;

        public KeywordController(IKeywordAppService keywordAppService)
        {
            _keywordAppService = keywordAppService;
        }

        /// <summary>
        /// 热门关键字
        /// </summary>
        /// <returns></returns>
        [DisableAuditing]
        public IActionResult Index()
        {
            return View();
        }

        public async Task<IActionResult> SwitchActive(Guid id,bool active)
        {
            await _keywordAppService.EditisActive(id,active);
            return Json(id);
        }

        [HttpGet]
        [DisableAuditing]
        [WrapResult(false, false)]
        public async Task<IActionResult> GetKeywordData(int page, int limit, string keyword="")
        {
            var model = await _keywordAppService.GetPagedListAsync(page,limit,keyword);
            return Json(model);
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <returns></returns>
        [DisableAuditing]
        public IActionResult Create()
        {
            return View();
        }

        public async Task<IActionResult> CreateKeyword(KeywordInput input)
        {
            var id = await _keywordAppService.Create(input);
            return Json(id);
        }
        /// <summary>
        /// 编辑
        /// </summary>
        /// 
        /// <param name="id"></param>
        /// <returns></returns>
        [DisableAuditing]
        public async Task<IActionResult> Edit(Guid id)
        {
            ViewBag.Id = id;
            var model = await _keywordAppService.GetByIdAsync(id);
            return View(model);
        }

        public async Task<IActionResult> EditKeyword(Guid id,KeywordInput input)
        {
            await _keywordAppService.Edit(id,input);
            return Json(id);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<IActionResult> Delete(Guid id)
        {
            await _keywordAppService.Delete(id);
            return Json(id);
        }
    }
}
